package com.asset.dispoal.evidenceType.service.commom;

import com.asset.dispoal.evidenceType.domain.db.entity.BsEvidenceType;
import com.asset.dispoal.evidenceType.domain.db.mapper.BsEvidenceTypeMapper;
import com.asset.dispoal.evidenceType.dto.BsEvidenceTypeRequest;
import com.asset.dispoal.evidenceType.service.converter.EvidenceTypeConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/3/24$
 */
@Component
public class EvidenceTypeInsertCommand implements BaseCommand<BsEvidenceTypeRequest, Result> {

    @Autowired
    BaseIdeable<String> snowFlake;

    @Autowired
    BsEvidenceTypeMapper bsEvidenceTypeMapper;

    @Override
    public Result execute(BsEvidenceTypeRequest request) {
        request.setId(snowFlake.generateId());
        BsEvidenceType bsEvidenceType = EvidenceTypeConverter.INSTANCE.reqToDo(request);
        bsEvidenceTypeMapper.insert(bsEvidenceType);
        return Result.ok();
    }
}
